use thiserror::Error;
use thiserror_exts::ErrorExt;

#[derive(Error, Debug, ErrorExt)]
pub enum AppError {
    #[error("data store disconnected")]
    IO {
        #[thiserror_exts(from)]
        source: std::io::Error,

        #[thiserror_exts(implicit)]
        location: thiserror_exts_impl::Location,
    },

    #[error("unknown data store error")]
    Unknown {
        #[from]
        source: std::num::ParseFloatError,
    },
}

//生成以下代码
// impl From<std::io::Error> for AppError {
//     #[track_caller]
//     fn from(error: std::io::Error) -> Self {
//         let l = std::panic::Location::caller();
//         AppError::Disconnect {
//             source: error,
//             location: thiserror_exts::Location::new(l.file(), l.line(), l.column()),
//         }
//     }
// }

pub fn main() -> Result<(), AppError> {
    std::fs::read_to_string("222")?;
    Ok(())
}
